/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elementsDefense.map;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import elementsDefense.map.Map.Dir;

/**
 *
 * @author Ricardo
 */
public class Tile {
    
    
    public static final int START = 1;
    public static final int PATH = 2;
    public static final int END = 4;
    public static final int GRASS = 8;
    
    public int x,y;
    public int type;
    
    public ArrayList<Dir> nextTiles=new ArrayList<Dir>(); 

    public Tile(int x, int y, int type) {
        this.x = x;
        this.y = y;
        this.type = type;
    }

    void save(DataOutputStream dataOutputStream) throws IOException {
        dataOutputStream.writeInt(type);
        dataOutputStream.writeInt(nextTiles.size());
        for (Dir dir : nextTiles) {
            dataOutputStream.writeInt(dir.ordinal());
        }
    }
    
    static Tile load(int x, int y, DataInputStream dataInputStream) throws IOException {
        int type = dataInputStream.readInt();
        Tile tile = new Tile(x, y, type);
        int nextTilesSize=dataInputStream.readInt();
        for (int i = 0; i < nextTilesSize; i++) {
            tile.nextTiles.add(Dir.values()[dataInputStream.readInt()]);
        }
        return tile;
    }
    
    
}
